package com.loiot.baqi.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.loiot.baqi.controller.response.Pager;
import com.loiot.baqi.dao.ZpAccountSalaryHistoryDao;
import com.loiot.baqi.service.ZpAccountSalaryHistoryService;
import com.loiot.commons.utils.DateUtil;
import com.loiot.baqi.pojo.ZpAccountSalaryHistory;
import com.loiot.baqi.dao.BaseDao;


/**
 * 文件上传下载 逻辑类。
 * 
 * @author  rick 
 * @creation 2016-10-26
 */
@Service("zpAccountSalaryHistoryService")
@Transactional
public class ZpAccountSalaryHistoryService{
    
    private Logger log = LoggerFactory.getLogger(this.getClass());
    
    @Autowired
	private ZpAccountSalaryHistoryDao zpAccountSalaryHistoryDao;
	
	 @Resource
	private BaseDao baseDao;
	
	
	 /**
     * 查询 文件上传下载列表分页
     * 
     * @param name 文件上传下载名称
     * @param pageIndex 页索引
     * @return
     */
    public Pager<ZpAccountSalaryHistory> queryZpAccountSalaryHistoryListPage(HashMap<String,Object> pMap, int pageIndex)throws Exception {

        // 查询文件上传下载列表总条数
        int totalResults = zpAccountSalaryHistoryDao.getZpAccountSalaryHistoryListCount(pMap);

        // 构造一个分页器
        Pager<ZpAccountSalaryHistory> pager = new Pager<ZpAccountSalaryHistory>(totalResults, pageIndex);

        // 查询文件上传下载列表
        List<ZpAccountSalaryHistory> zpAccountSalaryHistoryList = zpAccountSalaryHistoryDao.queryZpAccountSalaryHistoryList(pMap, pager.getSkipResults(),
                pager.getMaxResults());
        pager.setData(zpAccountSalaryHistoryList);
        return pager;
    }
    
    
    
    
    /**
     * 查询 文件上传下载（假）分页
     * 
     * @param name 文件上传下载名称
     * @param pageIndex 页索引
     * @return
     */
    public Pager<ZpAccountSalaryHistory> queryFlasePageList(HashMap<String,Object> pMap, int pageIndex)throws Exception {
    	//假分页
    	Pager<ZpAccountSalaryHistory> pager = this.setPkList(pMap,pageIndex);
    	List<ZpAccountSalaryHistory> zpAccountSalaryHistoryList = zpAccountSalaryHistoryDao.queryZpAccountSalaryHistoryList(pMap);
        pager.setData(zpAccountSalaryHistoryList);
        return pager;
    }
    
    /**
     * 设置 假分页id集合到Map中
     * @param pMap
     * @param pageIndex
     * @return
     * @throws Exception
     */
    public Pager<ZpAccountSalaryHistory> setPkList(HashMap<String,Object> pMap,int pageIndex) throws Exception{
    	  // 查询职位匹配信息列表总条数
        List<ZpAccountSalaryHistory> list = zpAccountSalaryHistoryDao.queryZpAccountSalaryHistoryList(pMap);
        // 构造一个分页器
        Pager<ZpAccountSalaryHistory> pager = new Pager<ZpAccountSalaryHistory>(list.size(), pageIndex, 5,list);
        List<ZpAccountSalaryHistory> idsList = pager.getCurrentPageData();
        List<Long> ids =this.getIds(idsList);
        pMap.put("ids", ids);
        return pager;
    }
	
	 /**
     * 添加 文件上传下载
     * 
     * @param p 参数对象
     */
    public ZpAccountSalaryHistory addZpAccountSalaryHistory(ZpAccountSalaryHistory p)throws Exception {
       return (ZpAccountSalaryHistory)baseDao.addV1(p);
    }
    
    /**
     * 修改 文件上传下载
     * 
     * @param p 参数对象
     */
    public void updateZpAccountSalaryHistory(ZpAccountSalaryHistory p)throws Exception {
    	baseDao.updateByPkV1(p);
    }
    
    
    
    /**
     * 删除  文件上传下载
     * 
     * @param id 主键
     */
    public void deleteZpAccountSalaryHistorybyPk(Class classsz,java.lang.Long id)throws Exception {
    	baseDao.deleteByPkV1(classsz,id);
    }
    
    /**
     * 删除  文件上传下载
     * 
     * @param id 主键
     */
    public void deleteZpAccountSalaryHistory(ZpAccountSalaryHistory p)throws Exception {
        zpAccountSalaryHistoryDao.deleteZpAccountSalaryHistory(p);
    }
    
    /**
     * 获得  文件上传下载
     * 
     * @param id 文件上传下载Id
     * 
     * @return 返回与ID匹配的文件上传下载
     */
    public ZpAccountSalaryHistory getZpAccountSalaryHistoryById(java.lang.Long id)throws Exception {
        return  zpAccountSalaryHistoryDao.getZpAccountSalaryHistoryById(id);
    }
    
    /**
     * 获得  文件上传下载
     * 
     * @param id 文件上传下载Id
     * 
     * @return 返回与ID匹配的文件上传下载
     */
    public ZpAccountSalaryHistory getZpAccountSalaryHistoryById(java.lang.Long id,Long accountId)throws Exception {
        return  zpAccountSalaryHistoryDao.getZpAccountSalaryHistoryById(id,accountId);
    }
    
    
    /**
     * 获得  文件上传下载
     * 
     * @param id 文件上传下载Id
     * 
     */
    public ZpAccountSalaryHistory getZpAccountSalaryHistory(HashMap<String,Object> pMap)throws Exception {
    	return (ZpAccountSalaryHistory) zpAccountSalaryHistoryDao.getZpAccountSalaryHistory(pMap);
    }
    /**
     * 获得  文件上传下载
     * 
     * @param name 文件上传下载名称
     * 
     * @return 返回与NAME匹配的文件上传下载
     */
    public ZpAccountSalaryHistory getZpAccountSalaryHistoryByName(String name)throws Exception {
        return  zpAccountSalaryHistoryDao.getZpAccountSalaryHistoryByName(name);
    }
    
    /**
     * 查询 文件上传下载列表
     * @return 文件上传下载列表
     */
    public List<ZpAccountSalaryHistory> queryZpAccountSalaryHistoryList(HashMap<String,Object> pMap)throws Exception {
        return  zpAccountSalaryHistoryDao.queryZpAccountSalaryHistoryList(pMap);
    }
    
    /**
     * 查询 文件上传下载列表
     * @return 文件上传下载列表
     */
    public List<ZpAccountSalaryHistory> queryZpAccountSalaryHistoryList(ZpAccountSalaryHistory p)throws Exception {
        return  zpAccountSalaryHistoryDao.queryZpAccountSalaryHistoryList(p);
    }
    
    /**
     * 查询  文件上传下载列表条数
     * 
     * @param name 文件上传下载名称
     * @return 文件上传下载列表条数
     */
    
    public int getZpAccountSalaryHistoryListCount(HashMap<String,Object> pMap)throws Exception {
        return  zpAccountSalaryHistoryDao.getZpAccountSalaryHistoryListCount(pMap);
    }
    
    /**
     * 查询id集合
     * @return
     */
    public List<Long> getIds(List<ZpAccountSalaryHistory> list) {
    	List<Long> idsList = null;
        if(list!=null && list.size()>0) {
        	idsList = new ArrayList<Long>();
        	for (ZpAccountSalaryHistory b : list) {
            	idsList.add(null);
            }
        }
        return idsList;
    }
    
    /**
     * 统计 文件上传下载列表
     * 
     * @return 文件上传下载列表
     */
    public List<HashMap<String,Object>> statisticsZpAccountSalaryHistoryInfo(HashMap<String, Object> pMap )throws Exception {
    	return  zpAccountSalaryHistoryDao.statisticsZpAccountSalaryHistoryInfo(pMap);
    }
    
    /**
     * TODO: 保存当前用户的薪资历史
     * @param userId 用户ID
     * @param type 薪资类型
     * @Auhor: RICK
     * @Date : 2016年10月26日
     */
    public ZpAccountSalaryHistory addZpAccountSalaryHistory(Long userId,Long type, double definePrice)throws Exception {
    	ZpAccountSalaryHistory history = new ZpAccountSalaryHistory();
    	history.setDefineId(type);//薪资定义类型
    	history.setDefinePrice(definePrice);//定义价格
    	history.setInTime(DateUtil.getCurrDateEndTime(new Date()));//录入时间
    	history.setEarningPersonId(userId);//收入人id
        return (ZpAccountSalaryHistory)baseDao.addV1(history);
     }
    
    
    
    /**
     * TODO: 通过用户ID查询用户薪资合计
     * @Auhor: RICK
     * @Date : 2016年10月26日
     */
    public long  getZpAccountSalaryHistorySum(HashMap<String,Object> pMap)throws Exception {
    	return zpAccountSalaryHistoryDao.getZpAccountSalaryHistorySum(pMap);
    }
    
}
